@model OrchardCore.ContentFields.ViewModels.EditLinkFieldViewModel
@using OrchardCore.ContentManagement.Metadata.Models
@using OrchardCore.ContentFields.Settings;
@{
    var settings = Model.PartFieldDefinition.Settings.ToObject<LinkFieldSettings>();
}

@{
    var isRequired = settings.Required && String.IsNullOrWhiteSpace(settings.DefaultUrl);
    var isTextRequired = settings.LinkTextMode == LinkTextMode.Required && String.IsNullOrWhiteSpace(settings.DefaultText);
    var urlClass = settings.Required ? "required" : null;
    var textClass = settings.LinkTextMode == LinkTextMode.Required ? "required" : null;
}

<div class="row">
    <fieldset class="form-group col-md-12">
        <label asp-for="Url">@Model.PartFieldDefinition.DisplayName()</label>
    </fieldset>
    <fieldset class="form-group col-md-6" asp-validation-class-for="Url">
        @if (string.IsNullOrEmpty(settings.UrlPlaceholder))
        {
            <label asp-for="Url" class="@urlClass">@T["Url"]</label>
        }
        <input asp-for="Url" class="form-control content-preview-text" placeholder="@settings.UrlPlaceholder" required="@isRequired" />
        @if (!string.IsNullOrWhiteSpace(settings.Hint))
        {
            <span class="hint">@settings.Hint</span>
        }
    </fieldset>
    @if (settings.LinkTextMode == LinkTextMode.Optional || settings.LinkTextMode == LinkTextMode.Required)
    {
        <fieldset class="form-group col-md-6" asp-validation-class-for="Text">
            @if (string.IsNullOrEmpty(settings.TextPlaceholder))
            {
                <label asp-for="Text" class="@textClass">@T["Link text"]</label>
            }
            <input asp-for="Text" type="text" class="form-control content-preview-text" placeholder="@settings.TextPlaceholder" required="@isTextRequired" />
            @if (!string.IsNullOrWhiteSpace(settings.HintLinkText))
            {
                <span class="hint">@settings.HintLinkText</span>
            }
        </fieldset>
    }
</div>
